// store.js
import { create } from 'zustand';
import { persist } from 'zustand/middleware';

// 定义一个带有多个状态的store
const useStore = create(
    persist(
        (set) => ({
            count: 0,
            platform_img: '/deep-seek.png',
            // 新建
            // company_img: '/新有梦.png',
            // text: '欢迎！新建区政务服务和数据管理局AI智能助手',
            // company_background: 'url(/新有梦background.png)',
            company_img: '/logo.png',
            company_background: 'url(/桑智background.jpg)',
            text: '',

            // 控制音频流的播放
            audioActive: -1,


            increment: (amount: number) => set((state: any) => ({ count: state.count + amount })),
            // 访问的设备
            getDevice: () => {
                if (typeof window !== 'undefined') {
                    if (window.innerWidth <= 600) {
                        return 'phone'
                    } else {
                        return 'computer'
                    }
                }
            },
            // 是否是文本编写
            getWord: () => {
                if (typeof window !== 'undefined') {
                    if (window.location.pathname === '/pages/WordButton') {
                        return false
                    }
                    return true
                }
            },
            // 移动端弹框
            open: false,
            setOpen: (open: boolean) => set(() => ({ open })),
            setaudioActive: (active: number) => { set({ audioActive: active }) }
        }),
        {
            name: 'my-app-storage',
            partialize: (state: any) => ({
                img: state.img
            }),
        }
    )
);

export default useStore;